package mx.com.fractal.ristorante.rest;

import javax.ejb.Singleton;
import javax.interceptor.Interceptors;
import javax.ws.rs.Consumes;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import mx.com.fractal.ristorante.dto.ErrorResponseDTO;
import mx.com.fractal.ristorante.dto.ReservacionDTO;
import mx.com.fractal.ristorante.service.ReservacionService;

import org.apache.log4j.Logger;
import org.jboss.resteasy.annotations.providers.jaxb.json.BadgerFish;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ejb.interceptor.SpringBeanAutowiringInterceptor;

@Path("reservacion")
@Singleton
@Interceptors(SpringBeanAutowiringInterceptor.class)
public class ReservacionRest {

	@Autowired
	private ReservacionService reservacionService;
	private static final Logger logger = Logger.getLogger(ReservacionRest.class);
	
	@PUT @Path("save") @BadgerFish
	@Consumes(value={MediaType.APPLICATION_XML,MediaType.APPLICATION_JSON})
	@Produces(value={MediaType.APPLICATION_XML,MediaType.APPLICATION_JSON})
	public Response save(ReservacionDTO reservacion){
		try {
			logger.trace("Guardando reservacion --> " + reservacion);
			reservacionService.save(reservacion);
		} catch (Exception e) {
			logger.error("Error al guardar la reservacion --> "+reservacion,e);
			return Response.serverError().entity(new ErrorResponseDTO(e.getMessage())).build();
		}
		return Response.ok().entity(reservacion).build();
		
	}
}
